﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class StuMessageEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region 判断Session["studentID"]是否为空，为空就返回
                if (Session["studentID"] == null)
                {
                    string strMsg = string.Format("alert('请不要非法登陆!这是不道德的行为！')");
                    ClientScript.RegisterStartupScript(this.GetType(), "", strMsg, true);
                    return;
                }
                #endregion

                HttpContext.Current.Response.Cache.SetNoStore();
                //取消页面的缓存
                HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            }
        }

        /// <summary>
        /// 将留言信息写入Message数据表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOK_Click(object sender, EventArgs e)
        {
            Model.Messages message = new Model.Messages()
            {
                mesStuNo = Session["studentID"].ToString(),
                mesTitle = txtCaption.Text.Trim(),
                mesDetail = txtContent.Text.Trim(),
            };
            BLL.MessageManager.AddMeeage(message);
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加留言成功!')", true);

            ////输出参数
            //Int32? result = -1;

            ////调用存储过程，将留言信息写入TB_Message数据表
            //LMSDataContext.GetLMSDB.sp_addMes(Session["studentID"].ToString(), DateTime.Now, txtCaption.Text, txtContent.Text, "待处理", "", "", ref result);


            //if (result == 1)
            //{
            //    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加留言成功!')", true);
            //}
            //else
            //{
            //    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加失败，请从新填写!')", true);
            //    txtContent.Text = "";
            //    txtCaption.Text = "";
            //}
        }


    }
}